/**
 * 2
 *  
 * @Author : roryrywang
 * @DateTime : 24-9-10 下午6:39
 */

#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     *
     * @param a string字符串
     * @param b string字符串
     * @return string字符串
     */
    string substr(string a, string b) {
        if (b.size() > a.size())return "";
        unordered_map<char, int> mapa;
        unordered_map<char, int> mapb;
        for (char ch: b) {
            mapb[ch]++;
        }
        int l = 0;
        int r = 0;
        int res = 0x3f3f3f3f;

        for (int i = 0, j = 0; j < a.size(); j++) {
            mapa[a[j]]++;
            while (check(mapa, mapb)) {
                if (res > j - i + 1) {
                    res = j - i + 1;
                    l = i;
                    r = j;
                }
                mapa[a[i]]--;
                i++;
            }
        }
        if (res < 0x3f3f3f3f) {
            return a.substr(l, r - l + 1);
        } else {
            return "";
        }
    }

    bool check(unordered_map<char, int> &mapa, unordered_map<char, int> &mapb) {
        for (auto e: mapb) {
            if (mapa[e.first] < e.second)return false;
        }
        return true;
    }
};

int main() {

    return 0;
}